package cn.zhaozhiqi.controller;

import cn.zhaozhiqi.domain.Login;
import cn.zhaozhiqi.exc.BussinessException;
import cn.zhaozhiqi.service.ILoginService;
import cn.zhaozhiqi.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private ILoginService loginService;


    @PostMapping("/account")
    public R loginByAccount(@RequestBody Login login){
        try {
            String token = loginService.loginByAccount(login);
            return R.ok("登录成功！",token);
        } catch (BussinessException e) {
            return R.fail(e.getMessage());
        }catch (Exception e){
            return R.fail("系统错误！！");
        }
    }

}
